package com.lagou.demo.service.impl;

import com.lagou.demo.service.ICheckAuthorityService;
import com.lagou.edu.mvcframework.annotations.LagouService;

import java.util.HashMap;
import java.util.Map;

@LagouService("checkAuthorityService")
public class CheckAuthorityServiceImpl implements ICheckAuthorityService {

    private static final Map<String,String[]> urlCheck;
    static {
        urlCheck = new HashMap<>();
        String[] demoQuery = new String[]{"zhangsan","lisi"};
        String[] demoHandle01 = new String[]{"wangwu","zhaoliu"};
        urlCheck.put("/demo/query",demoQuery);
        urlCheck.put("/demo/handle01",demoHandle01);
    }


    @Override
    public Boolean checkHasAuthority(String url ,String authorityName) {
        boolean flag = false;
        String[] names = urlCheck.get(url);
        if(names != null && names.length > 0){
            for(String name : names){
                if(name.equals(authorityName)){
                    flag = true;
                }
            }
        }
        return flag;
    }
}
